import React, { Component } from 'react'
import { Button, Text, TextInput, View } from 'react-native'

export default class StuAddor extends Component {
    state={stu:{}}
    _nameChange=name=>{
        let stu=this.state.stu
        stu.name=name
        this.setState({stu})
    }
    _add=()=>{
        let options={method:"POST",headers:{'Content-Type':'application/json'},
            body:JSON.stringify(this.state.stu)}
        fetch("http://172.16.1.151:3000/stus",options)
        .then(resp=>resp.json())
        .then(stu=>console.log(stu))
    }
    render() {
        return (
            <View>
                <TextInput value={this.state.stu.name} 
                onChangeText={this._nameChange}/>
                <Button title="添加" onPress={this._add}/>
            </View>
        )
    }
}
